<template>
  <div ref="chart" style="width: 500px; height: 300px"></div>
</template>

<script lang="ts" setup>
import { useTemplateRef, onMounted } from 'vue'
import * as echarts from 'echarts'

const chartEl = useTemplateRef<HTMLDivElement>('chart')
let myChart: echarts.ECharts | null = null
// 示例数据
const xData = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
const yData = [150, 230, 224, 218, 135, 147, 260]

onMounted(() => {
  myChart = echarts.init(chartEl.value!)
  const option = {
    title: {
      text: '柱状图示例',
    },
    tooltip: {
      trigger: 'axis',
    },
    xAxis: {
      type: 'category',
      data: xData,
    },
    yAxis: {
      type: 'value',
    },
    series: [
      {
        data: yData,
        type: 'bar',
        smooth: true,
        // 设置线条样式
        lineStyle: {
          width: 2,
        },
        // 设置区域填充样式
        areaStyle: {
          opacity: 0.3,
        },
        // 设置数据点样式
        itemStyle: {
          borderWidth: 2,
        },
      },
    ],
  }
  myChart.setOption(option)
})
</script>
